# Load the Shiny librarylibrary("shiny")# Define the User Interface (Frontend)ui <-fluidPage(titlePanel("Hello Shiny!"),sidebarLayout(sidebarPanel(sliderInput(inputId ="bins",label ="Number of bins:",min =1,max =50,value =30) ),mainPanel(plotOutput(outputId ="distPlot") ) ))# Define the Server (Backend)server <-function(input, output) { output$distPlot <-renderPlot({ x <- faithful$waiting bins <-seq(min(x), max(x), length.out = input$bins +1)hist(x, breaks = bins, col ="#75AADB", border ="white",xlab ="Waiting time to next eruption (in mins)",main ="Histogram of waiting times") })}# Launch the shiny appshinyApp(ui = ui, server = server)
Hello Shiny!
# Load the Shiny librarylibrary("shiny")# Define the User Interface (Frontend)ui <-fluidPage(titlePanel("Hello Shiny!"),sidebarLayout(sidebarPanel(sliderInput(inputId ="bins",label ="Number of bins:",min =1,max =50,value =30) ),mainPanel(plotOutput(outputId ="distPlot") ) ))# Define the Server (Backend)server <-function(input, output) { output$distPlot <-renderPlot({ x <- faithful$waiting bins <-seq(min(x), max(x), length.out = input$bins +1)hist(x, breaks = bins, col ="#75AADB", border ="white",xlab ="Waiting time to next eruption (in mins)",main ="Histogram of waiting times") })}# Launch the shiny appshinyApp(ui = ui, server = server)
Hello Shiny!
Frontend, the user interface
This is where the user interacts with your app
Chooses arguments to function parameters
Choices are “requests”
Backend, the server
This is where the computations are made in response to the user’s choices
Chosen arguments are passed to function parameters, producing an output
The output is the “response”
This frontend-to-backend continous communication is key!